#pragma strict
//////////////////////////////////////////////////////
///地形,助手
//////////////////////////////////////////////////////
class TerrainHelper{
	static var baseHeight:float = 1;
	/**
		根据xz坐标.获取地形高度.
	*/
	static function GetHeight(pos:Vector3,terrain:Terrain):float{
		var h:float = pos.y;
		if(terrain){
			var td:TerrainData = terrain.terrainData;
			var x:float = pos.x / td.size.x;
			var z:float = pos.z / td.size.z;
			h = terrain.terrainData.GetInterpolatedHeight(x,z);
		}else{
			var hit:RaycastHit;
			if(Physics.Raycast(Vector3(pos.x,100,pos.y),Vector3.down,hit)){
				h = hit.point.y;
			}
		}
		return h + baseHeight;
	}
	
	static function GetHeight(terrain:Terrain,pos:Vector3):float{
		return GetHeight(terrain,pos);
	}
	
}